package com.wjw.action;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Map;

//控制器
public class helloAction implements Action {
    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    //定义变量 接受页面的参数 与页面的name对应 并且提供set get方法
    private String userName;
    private String password;
    @Override
    public String execute() throws Exception {
        System.out.println(userName);
        //获取request
        //ActionContext.getContext().get("request");
        //解耦的方式获取session
        Map<String ,Object> session=ActionContext.getContext().getSession();
        session.put("userName",userName);
        session.put("password",password);
        //耦合的方式获取session
        HttpServletRequest request=ServletActionContext.getRequest();
//        HttpSession session2=request.getSession();
//        session2.setAttribute("userName",userName);
        //自定义逻辑字符串 与struts。xml的action->result标签里name对应
        return "success";
    }
}
